import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test06 {
    public static void main(String[] args) {
        File file=new File("D:\\aaa");
        HashMap<String,Integer> hm=getCount(file);
        System.out.println(hm);


    }
    public static HashMap<String,Integer> getCount(File src){
        HashMap<String,Integer> hm=new HashMap<>();
        File[] files=src.listFiles();
        if(files!=null){
            for(File file:files){
                if(file.isFile()){
                    String name=file.getName();
                    String[] arr=name.split("\\.");
                    if(arr.length==2){
                        String endName=arr[arr.length-1];
                        if(hm.containsKey(endName)){
                            int count=hm.get(endName);
                            count++;
                            hm.put(endName,count);
                        }
                        else{
                            hm.put(endName,1);
                        }

                    }
                }
                else{
                    HashMap<String,Integer> sonMap=getCount(file);
                    Set<Map.Entry<String, Integer>> entries=sonMap.entrySet();
                    for (Map.Entry<String,Integer> entry:entries){
                        String key=entry.getKey();
                        Integer value=entry.getValue();
                        if(hm.containsKey(key)){

                            value++;
                            hm.put(key,value);

                        }
                        else{
                            hm.put(key,1);
                        }
                    }


                }
            }

        }
        return hm;
    }
}
